package com.guowei.web.domain;

import java.io.File;

public class WebFileInfo {

    private String uri;

    private String filePath;

    private String fileName;

    private String fileType;

    private boolean folder;

    private long fileSize;

    private ByteUnit byteUnit;

    public WebFileInfo(String uri, File file) {
        this.uri = uri;
        this.filePath = file.getAbsolutePath();
        this.fileName = file.getName();
        if (this.fileName == null || this.fileName.trim().equals("")) {
            this.fileName = filePath;
        }
        if (file.isFile()) {
            int lastIndexOf = file.getName().lastIndexOf(".");
            if (lastIndexOf == -1) {
                this.fileType = "";
            } else {
                this.fileType = file.getName().substring(lastIndexOf + 1);
            }
            this.folder = false;
            this.fileSize = file.length();
            this.byteUnit = new ByteUnit(this.fileSize);
        } else {
            this.fileType = "folder";
            this.folder = true;
        }
    }

    public String getUri() {
        return uri;
    }

    public String getFilePath() {
        return filePath;
    }

    public String getFileName() {
        return fileName;
    }

    public String getFileType() {
        return fileType;
    }

    public boolean isFolder() {
        return folder;
    }

    public long getFileSize() {
        return fileSize;
    }

    public ByteUnit getByteUnit() {
        return byteUnit;
    }
}
